﻿#ifndef CUSTOMSPLITTER_H
#define CUSTOMSPLITTER_H

#include <QObject>
#include <QSplitter>
#include <QSplitterHandle>
#include <QPushButton>
#include <QToolButton>
#include "CommonPonents_global.h"

class COMMONPONENTS_EXPORT CustomSplitter : public QSplitter
{
    Q_OBJECT
public:
    explicit CustomSplitter(QWidget *parent = nullptr);

signals:
protected:
    QSplitterHandle *createHandle() override;
private slots:
    void onSplitterMoved(int pos,int index);
};



class COMMONPONENTS_EXPORT CustomSplitterHandle : public QSplitterHandle
{
    Q_OBJECT
public:
    explicit CustomSplitterHandle(Qt::Orientation orientation, QSplitter *parent = nullptr);
    void setBindForm(QWidget *form);
    bool checkFoldState(int pos);
protected:
    void resizeEvent(QResizeEvent *event) override;
    void showEvent(QShowEvent *event) override;
    void moveEvent(QMoveEvent *event) override;

private:
    QToolButton *m_toggleButton;
    QWidget *m_pForm;
    int m_nMinWidth;
    int m_nOldPos;
    void moveBtn();
private slots:
    void onButtonClicked(bool isFold);
};

#endif // CUSTOMSPLITTER_H


